#ifndef COM_H
#define COM_H

#include <QObject>
#include <QSerialPort>
#include <QFile>
#include <QDataStream>
#include <QMutex>
#include <QRegExp>
#include <QSemaphore>

class Com : public QObject
{
    Q_OBJECT
public:
    explicit Com(QString port_name,int rate,QObject *parent = 0);
	~Com();

	bool open(void);

private:
	bool read_data_running;
	QSerialPort port;
	QString		log_filename;
	QByteArray	receive_data;
	void Read_Data();

	QMutex rule_mutex;
	QList<QRegExp*> checklist;
	QString rule_result;
	QSemaphore *con_sem;
	void check_line(QString);
	void *add_check_rule(QString);
	void delete_rule(void *rule);

signals:
	void recv_data(QString);
	void style_change(int);

public slots:
	QString wait_string(QString str, int timeout_ms);
	int send(QByteArray);
};

#endif // COM_H
